/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CompanyInfo;
/*     */ import com.newcrm.bean.Group;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ 
/*     */ public class ShowCustomerTagChartData extends AbstractAction
/*     */ {
/*     */   public ShowCustomerTagChartData(AbstractHttpServlet servlet)
/*     */   {
/*  35 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  42 */     User user = super.getLoginUser(request);
/*  43 */     if ((!user.isAdmin) && (!user.isGroupAdmin)) {
/*  44 */       super.showErrorMessage(response, "只有管理员或者部门经理才有查看的权限");
/*  45 */       return;
/*     */     }
/*     */ 
/*  48 */     String userId = Util.getURLParameter(request.getParameter("userId"));
/*     */ 
/*  56 */     if (!user.isAdmin)
/*     */     {
/*  58 */       if ((userId == null) || (userId.trim().length() == 0) || 
/*  59 */         (userId.contains("*"))) {
/*  60 */         userId = "g_" + user.groupId;
/*     */       }
/*     */     }
/*     */ 
/*  64 */     CompanyInfo company = super.getCompany(request);
/*  65 */     List result = new ArrayList();
/*  66 */     CustomerManager manager = new CustomerManager();
/*     */ 
/*  68 */     if ((userId == null) || (userId.trim().length() == 0))
/*     */     {
/*  70 */       result = manager.getAllCustomerTagNum(user.companyId);
/*  71 */     } else if (userId.contains("u_")) {
/*  72 */       if (userId.indexOf("*") > 0) {
/*  73 */         userId = "";
/*     */       }
/*     */       else {
/*  76 */         userId = userId.substring(2);
/*  77 */         if (!user.isAdmin)
/*     */         {
/*  79 */           User viewUser = company.getUser(userId);
/*  80 */           if (viewUser == null) {
/*  81 */             super.showErrorMessage(response, "您查看的员工不存在");
/*  82 */             return;
/*     */           }
/*     */ 
/*  85 */           int userGroupId = viewUser.groupId;
/*  86 */           if (!company.isGroupAdmin(user, userGroupId)) {
/*  87 */             super.showErrorMessage(response, "您没有权限查看该员工的统计信息");
/*  88 */             return;
/*     */           }
/*     */         }
/*     */       }
/*  92 */       result = manager.getCustomerTagNumByUserId(user.companyId, userId);
/*  93 */     } else if (userId.contains("g_"))
/*     */     {
/*  95 */       int groupId = Util.str2Int(userId.substring(2));
/*  96 */       if (groupId <= 0) {
/*  97 */         super.showErrorMessage(response, "您查看的部门信息不存在");
/*  98 */         return;
/*     */       }
/*     */ 
/* 101 */       if (!company.isGroupAdmin(user, groupId)) {
/* 102 */         super.showErrorMessage(response, "您没有权限查看该员工的统计信息");
/* 103 */         return;
/*     */       }
/*     */ 
/* 106 */       String groupIds = "";
/*     */ 
/* 108 */       Group group = company.getGroupById(groupId);
/* 109 */       if (group == null) {
/* 110 */         super.showErrorMessage(response, "您查看的部门信息不存在");
/* 111 */         return;
/*     */       }
/* 113 */       groupIds = group.getAllIds();
/*     */ 
/* 115 */       result = manager.getCustomerTagNumByGroupIds(user.companyId, 
/* 116 */         groupIds);
/*     */     }
/*     */ 
/* 119 */     response.setContentType("text/html;charset=utf-8");
/* 120 */     PrintWriter out = response.getWriter();
/* 121 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/* 123 */     List chars = new ArrayList();
/* 124 */      for (Object itemO : result) {
        Map item = (Map)itemO;
/* 125 */       int num = Util.str2Int(item.get("totalNum"));
/* 126 */       int tagId = Util.str2Int(item.get("TagId"));
/* 127 */       String tagName = company.getCustomerTagName(tagId);
/* 128 */       if (tagName != null)
/*     */       {
/* 131 */         Map map = new HashMap();
/* 132 */         map.put("label", tagName);
/* 133 */         map.put("value", Integer.valueOf(num));
/* 134 */         map.put("id", Integer.valueOf(tagId));
/* 135 */         chars.add(map);
/*     */       }
/*     */     }
/* 138 */     jsonObject.put("error", "0");
/* 139 */     jsonObject.put("chars", chars);
/* 140 */     out.println(jsonObject);
/* 141 */     out.flush();
/* 142 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ShowCustomerTagChartData
 * JD-Core Version:    0.6.1
 */